using System;
using System.Collections.Generic;
using System.Text;
using OpenComposite.EII.Repository;

namespace OpenComposite.EII.Repository
{
	public class RepositoryItemKey : IEquatable<RepositoryItemKey>
	{
		#region Initialization
		//public RepositoryItemKey()
		//{
		//    this.Type = ItemType.Undefined;
		//    this.ID = -1;
		//}
		public RepositoryItemKey(ItemType type, int id)
		{
			this.Type = type;
			this.ID = id;
		}
		public RepositoryItemKey(IRepositoryItem item)
		{
			if ( item == null )
				throw new NullReferenceException("IRepositoryItem is null.");

			this.Type = item.RepositoryItemType;
			this.ID = item.ID;
		}

		#endregion

		#region Properties
		private ItemType _type;
		public ItemType Type
		{
			get { return _type; }
			set { _type = value; }
		}
		private int _id;
		public int ID
		{
			get { return _id; }
			set { _id = value; }
		}
		#endregion

		public override bool Equals(object obj)
		{
			RepositoryItemKey other = obj as RepositoryItemKey;
			if ( other != null )
				return ( this.Type == other.Type && this.ID == other.ID );
			else
				return false;
		}
		public override int GetHashCode()
		{
			return unchecked(( (int)this.Type ) + ( this.ID * 100 ));
		}

		#region IEquatable<RepositoryItemKey> Members

		public bool Equals(RepositoryItemKey other)
		{
			return ( this.Type == other.Type && this.ID == other.ID );
		}

		#endregion
	}
}
